#include "messageeditarea.h"
#include <QVBoxLayout>
#include <QPushButton>
#include <QHBoxLayout>

MessageEditArea::MessageEditArea(QWidget *parent)
    : QWidget{parent}
{
    //设置policy
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    setFixedHeight(180);

    //v + h 布局
    QVBoxLayout* vlayout = new QVBoxLayout();
    vlayout->setSpacing(0);
    vlayout->setContentsMargins(10, 1, 10, 10);
    setLayout(vlayout);

    QHBoxLayout* hlayout = new QHBoxLayout();
    hlayout->setSpacing(0);
    hlayout->setContentsMargins(0, 0, 0, 0);
    vlayout->addLayout(hlayout);
    hlayout->setAlignment(Qt::AlignLeft | Qt::AlignTop); //设置所有图标靠左


    QFrame *line = new QFrame();
    line->setFrameShape(QFrame::HLine);  // 水平线
    line->setFrameShadow(QFrame::Plain); // 无阴影
    line->setStyleSheet("QFrame { border: none; background-color: #e6e6e6; }"); // 纯色背景
    line->setFixedHeight(1);             // 高度设为1px
    line->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); // 宽度填满
    vlayout->insertWidget(0, line);      // 插入到布局顶部

    QString btnSS = "QPushButton {border:none; background-color: transparent;}";
    btnSS += "QPushButton:pressed {background-color: rgb(210, 210, 210)}";
    QSize btnSize(35, 35);
    QSize iconSize(25, 25);

    imageBtn = new QPushButton();
    imageBtn->setFixedSize(btnSize);
    imageBtn->setIconSize(iconSize);
    imageBtn->setIcon(QIcon(":/resource/images/image.png"));
    imageBtn->setStyleSheet(btnSS);

    fileBtn = new QPushButton();
    fileBtn->setFixedSize(btnSize);
    fileBtn->setIconSize(iconSize);
    fileBtn->setIcon(QIcon(":/resource/images/file.png"));
    fileBtn->setStyleSheet(btnSS);


    speechBtn = new QPushButton();
    speechBtn->setFixedSize(btnSize);
    speechBtn->setIconSize(iconSize);
    speechBtn->setIcon(QIcon(":/resource/images/sound.png"));
    speechBtn->setStyleSheet(btnSS);

    historyBtn = new QPushButton();
    historyBtn->setFixedSize(btnSize);
    historyBtn->setIconSize(iconSize);
    historyBtn->setIcon(QIcon(":/resource/images/history.png"));
    historyBtn->setStyleSheet(btnSS);

    hlayout->addWidget(imageBtn);
    hlayout->addWidget(fileBtn);
    hlayout->addWidget(speechBtn);
    hlayout->addWidget(historyBtn);

    textEdit = new QPlainTextEdit();
    textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    textEdit->setStyleSheet(
        "QPlainTextEdit {"
        "    background-color: transparent;"  // 设置背景色
        "    border: none;    "
        "    padding-left: 10px;"
        "    font-size: 14px;"
        "}"
        "QScrollBar:vertical {"          // 垂直滚动条
        "    width: 7px;"               // 宽度
        "    background: #f1f1f1;"       // 背景色
        "}"
        "QScrollBar::handle:vertical {"  // 滚动条滑块
        "    background: #888;"          // 滑块颜色
        "    min-height: 20px;"          // 滑块最小高度
        "    border-radius: 3px;"        // 圆角
        "}"
        "QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {"  // 上下箭头
        "    background: none;"          // 隐藏默认箭头
        "}"
        );
    vlayout->addWidget(textEdit);

    sendBtn = new QPushButton();
    sendBtn->setFixedSize(115, 40);
    sendBtn->setText("发送");
    sendBtn->setStyleSheet("QPushButton {background-color: rgb(233, 233, 233); color: rgb(80, 186, 131);"
                           "border-radius: 10px; font-size: 16px}"
                           "QPushButton:hover {background-color: rgb(210, 210, 210);}"
                           "QPushButton:pressed {background-color: rgb(190, 190,190)}");
    vlayout->addWidget(sendBtn, 0, Qt::AlignRight | Qt::AlignCenter);
}

